﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Wicture.DbRESTFul;
using Wicture.QPZS.EPC.API.Domain.Entities;

namespace Wicture.QPZS.EPC.API.InvokeContextBuilders
{
    public class AccountThrottlingBuilder : IThrottlingContextBuilder
    {
        public decimal Order => 0;

        public void Build(ThrottlingContext context, object sender, ApiInvokingArgs e)
        {
            var success = int.TryParse(e.Context.Identity.Id, out int accountId);
            if (!success)
            {
                throw new LogicalException("未检测到用户Id");
            }
            context.AccountId = accountId;
            context.ApiName = e.Context.Api.name;
            context.AccountName = e.Context.Identity.Name;
        }
    }
}
